<template>
	<view style="display: flex;flex-direction: column;background-color: #f3f7fe;padding: 30rpx;min-height: 100vh;">
		<view style="background-color: #fff;padding: 20rpx;border-radius: 20rpx">
			<view class="header"
				style="display: flex;justify-content: space-between;border-bottom: 1px solid #f3f7fe;padding-bottom: 30rpx;">
				<div style="display: flex;align-items: center;">
					<div
						style="background-color: rgb(85, 177, 249); padding: 3rpx; width: 70rpx; height: 70rpx; color: rgb(255, 255, 255); display: flex; justify-content: center; align-items: center; border-radius: 10rpx;">
						{{data.name}}
					</div>
					<div style="display: flex; flex-direction: column; justify-content: center; margin-left: 20rpx;">
						<span style="margin-bottom: 5px;">{{data.lastName}}</span>
						<span style="font-size: 12px;color: rgb(153, 153, 153);">{{data.departName}}</span>
					</div>
				</div>

				<div class="header-menu">
					<div class="mint-navbar">
						<a :class="type ==0?'mint-tab-item is-selected':'mint-tab-item'" @click="changeType(0)">
							<div class="mint-tab-item-label">日</div>
						</a>
						<a :class="type ==1?'mint-tab-item is-selected':'mint-tab-item'" @click="changeType(1)">
							<div class="mint-tab-item-label">周</div>
						</a>
						<a :class="type ==2?'mint-tab-item is-selected':'mint-tab-item'" @click="changeType(2)">
							<div class="mint-tab-item-label">月</div>
						</a>
					</div>
				</div>
			</view>

			<view class="calendar_container">
				<dayCalendar  :date="date" v-if="type == 0" :sundayIndex="6" mode="close" @change="change" />
				<monthCalendar :date="date" v-if="type == 1" :sundayIndex="6" mode="close" @change="change" />
				<yearCalendar :date="date" v-if="type == 2" :sundayIndex="6" mode="close" @change="change" />
			</view>
			<!-- 日统计 -->
			<view v-if="type == 0" class="data_person_day">
				<view class="tip">
					<span style="margin-bottom: 10rpx;">当日班次:{{data.dataForDay.serialInfo}}</span>
				</view>
				<view style="display: flex;flex-direction: column;padding: 20rpx;">
					<view v-for="item in data.dataForDay.workflow" style="display: flex;border: 1px solid #eee;padding: 25rpx;border-radius: 20rpx;justify-content: space-between;margin-bottom: 10rpx;" @click="toWorkflow(item.requestId)">
						
						<view style="display: flex;align-items: center;">
							<img :src="icon" alt="" style="width:40rpx;height: 40rpx;">
							<span style="margin-left: 20rpx;font-weight: 600;">{{item.type}}</span>
						</view>
						<view style="display: flex;align-items: center;">
							<span style="font-size: 14px;color: #999;margin-right: 10rpx;">已通过</span>
							<van-icon name="arrow" />
						</view>
						
					</view>
					
					
				</view>
				
				
				<view>
                    <van-empty v-if="Object.keys(data.dataForDay).length == 0 || data.dataForDay.signInfo.length == 0" description="暂无考勤数据" />
					<Timeline v-else title="打卡明细" :data-list="data.dataForDay.signInfo">
					</Timeline>
				</view>
			</view>
			<!-- 日统计 -->
			<!-- 周统计 -->
			<view v-if="type == 1" class="data_person_day">
				<van-grid :column-num="3" :border="false">
					<van-grid-item>
						<span>0</span>
						<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">工作时长</span>
					</van-grid-item>
					<van-grid-item>
						<span>0</span>
						<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">出勤天数</span>
					</van-grid-item>
					<van-grid-item>
						<span>0</span>
						<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">迟到</span>
					</van-grid-item>
					<van-grid-item>
						<span>0</span>
						<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">早退</span>
					</van-grid-item>
					<van-grid-item>
						<span>0</span>
						<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">漏签</span>
					</van-grid-item>
					<van-grid-item>
						<span>0</span>
						<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">矿工</span>
					</van-grid-item>
					<van-grid-item>
						<span>0</span>
						<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">请假</span>
					</van-grid-item>
					<van-grid-item>
						<span>0</span>
						<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">加班</span>
					</van-grid-item>


				</van-grid>
			</view>
			<!-- 周统计 -->
			<!-- 周统计 -->
			<view v-if="type == 2" class="data_person_day">
				<van-grid :column-num="3" :border="false">
				<van-grid-item>
					<span>0</span>
					<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">工作时长</span>
				</van-grid-item>
				<van-grid-item>
					<span>0</span>
					<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">出勤天数</span>
				</van-grid-item>
				<van-grid-item>
					<span>0</span>
					<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">迟到</span>
				</van-grid-item>
				<van-grid-item>
					<span>0</span>
					<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">早退</span>
				</van-grid-item>
				<van-grid-item>
					<span>0</span>
					<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">漏签</span>
				</van-grid-item>
				<van-grid-item>
					<span>0</span>
					<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">矿工</span>
				</van-grid-item>
				<van-grid-item>
					<span>0</span>
					<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">请假</span>
				</van-grid-item>
				<van-grid-item>
					<span>0</span>
					<span style="margin-top: 30rpx; font-size: 12px; color: rgb(158, 165, 183);">加班</span>
				</van-grid-item>


				</van-grid>
			</view>
			<!-- 周统计 -->
			<view style="font-size: 12px;color:#999 ;">统计结果至&nbsp;{{data.lasttime}}</view>
		</view>
	</view>
</template>

<script>
	import dayCalendar from '@/components/zsy-calendar/day-calendar'
	import monthCalendar from '@/components/zsy-calendar/month-calendar'
	import yearCalendar from '@/components/zsy-calendar/year-calendar'
	import Timeline from '@/components/Timeline'
	import {
		parseTime,
	} from '@/components/zsy-calendar/js/utils.js'
	
	import ic from '@/static/qj.png'
	export default {
		components: {
			dayCalendar,
			monthCalendar,
			yearCalendar,
			Timeline
		},
		created() {
			if (this.$route.query.type !== undefined) {
				this.type = this.$route.query.type
			}
			if(this.$route.query.startDate !=undefined && this.$route.query.startDate !=''){
				 if(this.$route.query.lx == '2'){
					 this.date = this.$route.query.startDate+'-01'
				 }else{
					 this.date = this.$route.query.startDate
				 }
			}
			
		},
		data() {
			return {
				icon:ic,
				date:parseTime(new Date(), '{y}-{m}-{d}'),
				type: 0,
				data: {
					lastName: '',
					departName: '',
					name: '',
					dataForDay: {
						workflow:[],
						signInfo:[]
						 
					},
					dataForWeek: {
						 
					},
					dataForMonth: {
						 
					},
					lasttime:''
				}


			}
		},
		methods: {
			toWorkflow(requestId){
			   	window.open('/spa/workflow/static4mobileform/index.html#/req?requestid='+requestId+'&ismonitor=1')
			},
			init(startDate,endDate,lx) {
				uni.request({
					url: '/mobile/heo/AttendForPerson.jsp',
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						startDate: startDate,
						endDate: endDate,
						lx: lx,
						scope: this.$route.query.scope,
						userId: this.$route.query.userId,
					},
					success: (res) => {
						const result = res.data;
						if (result.ret === '0') {
							this.data = result.data
						} else {

						}

					}

				})

			},
			change(e) {
				console.log(e)
				if(e.type == 'day'){
					this.init(e.selectedDate,e.selectedDate,1)
					
				}else if(e.type == 'week'){
					if(e.selectedDate.length == 7){
						this.init( parseTime(new Date(e.selectedDate[0].year, e.selectedDate[0].month- 1, e.selectedDate[0].date), '{y}-{m}-{d}'),parseTime(new Date(e.selectedDate[6].year, e.selectedDate[6].month- 1, e.selectedDate[6].date), '{y}-{m}-{d}'),2)
					}
					
				}else if(e.type == 'month'){
					
				}
			},
			changeType(type) {
				this.type = type
			}
		}
	}
</script>

<style scoped>
	.mint-navbar {
		height: 0.5rem;
		display: flex;
		background-color: #9ea5b7;
		padding: 0.1rem;
		border-radius: 0.1rem;
		margin-top: 0.2rem;
	}

	.header-menu {
		display: flex;
		align-items: center;
	}

	.mint-navbar {
		height: 50rpx;
		display: flex;
		background-color: #9ea5b7;
		padding: 10rpx;
		border-radius: 10rpx;
	}

	.is-selected {
		background-color: #FFF;
		border-radius: 10rpx;
		font-weight: 600;
	}

	.mint-tab-item {
		flex: 1;
		color: #000;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 12px;
		width: 90rpx;
		cursor: pointer;
	}

	.data_person_day {
		min-height: 400rpx;
	}

	.tip {
		display: flex;
		flex-direction: column;
		font-size: 12px;
		color: #999;
	}
</style>
